package com.eduhzy.ttw.teacher.di.module;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.blankj.utilcode.util.TimeUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.eduhzy.ttw.commonsdk.entity.PlatformNoticeData;
import com.eduhzy.ttw.commonsdk.holder.AutoBaseViewHolder;
import com.eduhzy.ttw.teacher.R;
import com.eduhzy.ttw.teacher.mvp.contract.PlatformNoticeContract;
import com.eduhzy.ttw.teacher.mvp.model.PlatformNoticeModel;
import com.jess.arms.di.scope.ActivityScope;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import dagger.Binds;
import dagger.Module;
import dagger.Provides;

/**
 * @author xubo
 * @date 2018-7-20 16:41:22
 */
@Module
public abstract class PlatformNoticeModule {

    @Binds
    abstract PlatformNoticeContract.Model bindPlatformNoticeModel(PlatformNoticeModel model);

    @ActivityScope
    @Provides
    static List<PlatformNoticeData> provideList() {
        return new ArrayList<>();
    }

    @ActivityScope
    @Provides
    static RecyclerView.LayoutManager provideLayoutManager(PlatformNoticeContract.View view) {
        return new LinearLayoutManager(view.getActivity());
    }

    @ActivityScope
    @Provides
    static BaseQuickAdapter<PlatformNoticeData, AutoBaseViewHolder> provideActivityAdapter(List<PlatformNoticeData> list) {
        return new BaseQuickAdapter<PlatformNoticeData, AutoBaseViewHolder>(R.layout.rv_item_platform_notice, list) {
            @Override
            protected void convert(AutoBaseViewHolder helper, PlatformNoticeData item) {
                helper.setText(R.id.tv_title, item.getTitle());
                helper.setText(R.id.tv_content, item.getContent());
                helper.setText(R.id.tv_time, TimeUtils.millis2String(item.getSendDate(), new SimpleDateFormat("MM-dd")));
                helper.setGone(R.id.tv_unread, item.getHasRead() == 0);
            }
        };
    }
}